<?php
ob_start();
require_once('lib/database.php');
require_once('lib/user.php');

if(isset($_POST['submit'])){

	if(!empty($_POST['username']) || !empty($_POST['password'])){
	
		if($_POST['password'] == $_POST['password2']){
		
			$user = User::find_by_username($_POST['username']);
			
			if($user->username == $_POST['username']){
			
				echo "username already exist";
		
			} else {
			
				$user->insert('portal', $_POST['username'], $_POST['password']);
				echo "Registration Successful!";
				header("location: http://localhost/crud/login.php");
			
			}
		
		
		}
	
	}

}
	
?>

<form action="signup.php" method="post">
	<label for="username">Username</label>
	<input type="text" name="username" />
	<label for="password">Password</label>
	<input type="password" name="password" />
	<label for="password2">Confirm Password</label>
	<input type="password" name="password2" />
	<input type="submit" value="Sign Up" name="submit">
</form>
<?php ob_flush(); ?>